﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kocic.RepositoryManagement.LinqToSql;
using Sample.LinqToSql.Model;

namespace Sample.Run.LinqToSql
{
    public class PersonRepositoryManager : LinqToSqlRepositoryManager<Person, SampleDataModelClassesDataContext>
    {
        public PersonRepositoryManager()
        {

        }

        public PersonRepositoryManager(SampleDataModelClassesDataContext context)
            : base(context)
        {

        }

        public override Person RetrieveSingle(object searchValue)
        {
            return this.DataSource.Persons.Where(p => p.id == Convert.ToInt32(searchValue)).SingleOrDefault();
        }

        public override IEnumerable<Person> RetrieveMultiple()
        {
            return this.DataSource.Persons.Select(p => p);
        }

        public override IEnumerable<Person> RetrieveMultiple(object searchValue)
        {
            throw new NotImplementedException();
        }

        public Person RetrieveSingle(String firstName, String LastName)
        {
            return this.DataSource.Persons.Where(p => p.FirstName == firstName && p.LastName == LastName).SingleOrDefault();
        }

        protected override Person PreDelete(Person dataObject)
        {
            Person original = this.RetrieveSingle(dataObject.id);

            return original;
        }
    }
}
